<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1500" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-header>
                <div class="left-panel">
                    <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'project.add'"></el-button>
                </div>
                <div class="right-panel">
                    <div class="right-panel-search" style="flex-wrap:wrap;">
                        <el-input style="margin:5px 10px" v-model="search.project_code" placeholder="请输入项目编号" clearable @keyup.enter="upsearch"></el-input>
                        <el-input style="margin:5px 10px" v-model="search.company_name" placeholder="请输入客户名称" clearable @keyup.enter="upsearch"></el-input>
                        <el-input style="margin:5px 10px" v-model="search.metting" placeholder="请输入会议名称" clearable @keyup.enter="upsearch"></el-input>
                        <el-date-picker v-model="search.project_time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 230px" />
                        <el-select v-model="search.type" placeholder="请选择类型" clearable filterable>
                            <el-option v-for="item in typeList" :key="item.id" :label="item.title" :value="item.id"/>
                        </el-select>
                        <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-refresh" @click="refresh">重置</el-button>
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :apiObj="apiObj" remoteSort remoteFilter border height="600" :params="query">
                    <el-table-column width="1"></el-table-column>
                    <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                    <el-table-column label="项目编号" prop="project.project_code" align="center"></el-table-column>
                    <el-table-column label="会议名称" prop="project.metting" align="center"></el-table-column>
                    <el-table-column label="宴会厅名称" prop="project.banquet.banquet_name" align="center"></el-table-column>
                    <el-table-column label="会议日期" prop="project.project_time" align="center">
                        <!-- <template #default="scope">
                            {{ moment(scope.row.project.project_time * 1000).format('YYYY-MM-DD') }}
                        </template> -->
                    </el-table-column>
                    <el-table-column label="预售金额" prop="pre_sale" align="center"></el-table-column>
                    <el-table-column label="拍照上传" prop="photo_files" align="center">
                        <template #default="scope">
                            <el-image class="img" :src="(scope.row.photo_files).split(',')[0]" :preview-src-list="(scope.row.photo_files).split(',')" fit="cover" preview-teleported="true" hide-on-click-modal />
                        </template>
                    </el-table-column>
                    <el-table-column label="预售状态" prop="pre_status" align="center">
                        <template #default="scope">
                            <el-tag v-if="scope.row.pre_status == 0" type="success">预售中</el-tag>
                            <el-tag v-else-if="scope.row.pre_status == 1" type="danger">已退款</el-tag>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
        <save-add v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-add>
	</el-dialog>
</template>

<script>
import saveAdd from './project.vue'
export default {
    components: { saveAdd },
    props:{
        query: { type: String, default: "" },
    },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '查看项目',
				edit: '编辑产品',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.project.hotel.list,
			selection: [],
			search: {
				project_code: null,
				metting: null,
				project_time: null,
				banquet_name: null,
				pre_status: 0,
			},
            dialog: {
				save: false,
			},
            typeList:[
                {id:1,title:"会议"},
                {id:2,title:"婚礼"},
                {id:3,title:"会议代收"},
                {id:4,title:"会议代收+自付"},
                {id:5,title:"赞助"},
            ],
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单注入数据
		setData(data) {
			//可以和上面一样单个注入，也可以像下面一样直接合并进去
            this.form.id = data.id
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
        //客户新增
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
        // 更新客户新增
        handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
	}
}
</script>

<style></style>
